{{ define "page" }}
    <div class="form-group pull-right">
        <div class="input-group">
            <label class="btn-group">
                <a href="?action=user" class="btn btn-success btn-sm">
                    <i class="fas fa-user-plus" title="{{ i18n "Create user" . }}"></i> {{ i18n "Create user" . }}
                </a>
                <a href="?action=group" class="btn btn-success btn-sm">
                    <i class="fas fa-users" title="{{ i18n "Create group" . }}"></i> {{ i18n "Create group" . }}
                </a>
            </label>
        </div>
    </div>

    <table class="table table-striped dt-responsive nowrap" style="width:100%" id="accounts">
        <thead>
        <tr>
            <th>{{ i18n "User" . }}</th>
            <th>{{ i18n "Comment" . }}</th>
            <th>{{ i18n "Actions" . }}</th>
        </tr>
        </thead>
        <tbody>
        {{ range $group := .groups }}
            <tr class="group">
                <td colspan="2">
                    {{ $group.Name }}{{ if $group.Memo }} ({{ $group.Memo }}){{ end }}
                </td>
                <td class="text-right">
                    <div{{ if ne $group.CanRemove true }} class="btn-group" role="group"{{ end }}>
                        {{ if $group.CanRemove }}
                        <form method="post" action="{{ $.Request.URL.Path }}?action=group-delete&groupname={{ $group.Name }}" class="btn-group" role="group">
                        {{ end }}

                            <a href="{{ $.Request.URL.Path }}?action=user&groupname={{ $group.Name }}" class="btn btn-success btn-icon btn-xs">
                                <i class="fas fa-user-plus" title="{{ i18n "Add user to group" $ }}"></i>
                            </a>

                            <a href="{{ $.Request.URL.Path }}?action=group&groupname={{ $group.Name }}" class="btn btn-info btn-icon btn-xs">
                                <i class="fas fa-edit" title="{{ i18n "Edit group" $ }}"></i>
                            </a>

                        {{ if $group.CanRemove }}
                            <button type="submit" class="btn btn-danger btn-icon btn-xs">
                                <i class="fas fa-trash" title="{{ i18n "Remove group" $ }}"></i>
                            </button>
                        </form>
                        {{ end }}
                    </div>
                </td>
            </tr>
            {{ range $user := $.users }}
                {{ if eq $group.Name $user.Group }}
                <tr{{ if eq $user.Name $.current }} class="success"{{ end }}>
                    <td>{{ $user.Name }}</td>
                    <td>{{ $user.Memo }}</td>
                    <td class="text-right">
                        <div{{ if or ($user.Reserved) (eq $user.Name $.current) }} class="btn-group" role="group"{{ end }}>
                            {{ if and (ne $user.Reserved true) (ne $user.Name $.current) }}
                            <form method="post" action="{{ $.Request.URL.Path }}?action=user-delete&username={{ $user.Name }}" class="btn-group" role="group">
                            {{ end }}

                            <a href="{{ $.Request.URL.Path }}?action=user&username={{ $user.Name }}" class="btn btn-info btn-icon btn-xs">
                                <i class="fas fa-user-edit" title="{{ i18n "Edit user" $ }}"></i>
                            </a>
                            <a href="{{ $.Request.URL.Path }}?action=password&username={{ $user.Name }}" class="btn btn-warning btn-icon btn-xs">
                                <i class="fas fa-user-lock" title="{{ i18n "Change user password" $ }}"></i>
                            </a>

                            {{ if and (ne $user.Reserved true) (ne $user.Name $.current) }}
                                <button type="submit" class="btn btn-danger btn-icon btn-xs">
                                    <i class="fas fa-user-times" title="{{ i18n "Remove user" $ }}"></i>
                                </button>
                            </form>
                            {{ end }}
                        </div>
                    </td>
                </tr>
                {{ end }}
            {{ end }}

        {{ end }}
        </tbody>
    </table>
{{ end }}

{{ define "js" }}
    {{ staticHTML (staticURL "/dashboard/assets/vendors/validator/js/validator.min.js" false) }}
{{ end }}